package com.wangshb.upms.generate.generate;

import com.wangshb.upms.generate.Configuration;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 创建java代码
 */
public class VueGenerate extends AbstractGenerate {


    public VueGenerate(Configuration configuration) {
        super(configuration);
    }

    @Override
    public File getFile() {

        Configuration configuration = getConfiguration();

        //1. 创建java - entity 代码
        String tableName = configuration.getTableEntity().getTableName();
        String systemName = tableName.substring(0, tableName.indexOf("_"));
        String jsParentPath = configuration.getJsSrcPath() + "\\views\\" + systemName + "\\" + replaceUnderLineAndUpperCase(tableName.substring(tableName.indexOf("_") + 1), true);
        File dirFile = new File(jsParentPath);
        if (!dirFile.exists()) {
            dirFile.mkdirs();
        }
        return new File(dirFile.getAbsolutePath() + "\\index.vue");
    }

    @Override
    public Map<String, Object> getTemplateParams() {
        String tableName = getConfiguration().getTableEntity().getTableName();
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("system_name", tableName.substring(0, tableName.indexOf("_")));
        dataMap.put("search_columns", getConfiguration().getSearchColumnList());
        dataMap.put("table_entity", getConfiguration().getTableEntity());
        dataMap.put("property_columns", getConfiguration().getTableEntity().getColumnPropertyList());
        dataMap.put("request_url",tableName.substring(0, tableName.indexOf("_")) + "/" + replaceUnderLineAndUpperCase(tableName.substring(tableName.indexOf("_") + 1), true));
        return dataMap;
    }

    @Override
    public String getTemplateName() {
        return "templates/pc-vue.ftl";
    }
}
